package dao.impl;

import dao.IShopCarDao;
import model.ShopCar;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @aythor:侯仪澳
 * @data:2022/8/4
 */
@Repository
public class ShopCarDao implements IShopCarDao {
    @Autowired
    private SqlSession sqlSession;
    String url = "dao.IShopCarDao.";

    //添加到购物车
    @Override
    public int addOneGoodsToCar(ShopCar shopCar) {
        return sqlSession.insert(url + "addOneGoodsToCar",shopCar);
    }

    //查询购物车
    @Override
    public List<ShopCar> queryShopCar(ShopCar shopCar) {
        return sqlSession.selectList(url + "queryShopCar",shopCar);
    }

    @Override
    public ShopCar queryShopCarExist(ShopCar shopCar) {
        return sqlSession.selectOne(url + "queryShopCarExist",shopCar);
    }

    @Override
    public int deleteShopCar(Integer id) {
        return sqlSession.delete(url + "deleteShopCar",id);
    }

    //若购物车里存在该商品，数量加到原来商品的数量之上
    @Override
    public int updateShopCar(ShopCar shopCar) {
        return sqlSession.update(url + "updateShopCar",shopCar);
    }
}
